<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>采购单列表 - 仓库管理系统</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;top: 0px;">

    <!-- start sp-wrapper -->
    <link rel="stylesheet" href="/sb/stock.css"/>
    <div class="sp-wrapper">
        <h2 class="sp-title"><a href="/stock_in/purchase_list">待入库</a> <a class="active">已入库</a></h2>
        <div class="sp-tool">
            <span class="fl">
                <form action="/stock_in/purchase_put" method="get">
                    <b>
                        <input type="text" th:value="${startDate}" name="startDate" class="date" autocomplete="off"
                               placeholder="开始日期"> -
                        <input type="text" th:value="${endDate}" name="endDate" class="date1" autocomplete="off"
                               placeholder="结束日期">
                    </b>
                    <b><input type="text" id="billNo" name="billNo" autocomplete="off" th:value="${billNo}"
                              placeholder="输入单据编号查询"></b>
                    <b><input type="submit" class="button" value="查询"></b>
                </form>
            </span>
        </div>
        <div class="sp-table">
            <table>
                <thead>
                <tr>
                    <th>序号</th>
                    <th>单据编号</th>
                    <th>入库时间</th>
                    <th>入库数量</th>
                    <th>操作人</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="sp-data">
                <tr th:each="item:${list}">
                    <td></td>
                    <td th:text="${item.billNo}">华衣</td>
                    <td th:text="${item.stockInTimes}"></td>
                    <td th:text="${item.inQuantity}"></td>
                    <td th:text="${item.stockInName}">华衣</td>
                    <td>
                        <i class="detail" th:attr="data-id=${item.id}">详情</i>
                        <!--                            <a th:href="${'/purchase/detail?id='+item.id}" target="_blank">打印采购单</a>-->
                        <i class="print" th:attr="data-id=${item.id}">打印</i>
                    </td>
                </tr>

                </tbody>
            </table>

        </div>
        <div class="pages">
            <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
        </div>
    </div>
    <script type="text/javascript" src="/sb/jquery.min.js"></script>
    <script type="text/javascript" src="/sb/Tips.min.js"></script>
    <style type="text/css">
        .check-box {
            position: relative;
            width: 900px;
            padding: 0 5px;
            font-size: 13px;
            color: #787878;
        }

        .check-info {
            line-height: 40px;
            overflow: hidden;
        }

        .check-info span {
            float: left;
            width: 18%;
            text-align: center;
        }

        .check-info span:nth-child(1) {
            width: 30%;
            text-align: left;
        }

        .check-info span:nth-child(5) {
            width: 16%;
            text-align: right;
        }

        .check-table {
            margin: 10px 0;
            /*max-height: 250px;*/
            overflow-y: auto;
        }

        .check-table table {
            width: 100%;
        }

        .check-table th, .check-table td {
            padding: 10px 0;
            font-size: 13px;
            text-align: center;
            border: 1px solid #787878;
        }

        .check-table th {
            padding: 5px 0;
        }
    </style>
    <script type="text/template" id="tpl-1">
        <div class="check-box">
            <div class="check-info">
                <span>单据编号：<i id="r-number">CG190411100335401</i></span>
                <span>单据日期：<i id="r-time">2019-04-11</i></span>
                <span>采购数量：<i id="r-count">2000</i></span>
                <span>制单人：<i id="r-name">张三</i></span>
                <span>供应商：<i id="r-trader">华衣</i></span>
            </div>
            <div class="check-table">
                <table>
                    <thead>
                    <tr>
                        <th>SKU</th>
                        <th>商品</th>
                        <th>规格</th>
                        <th>库位信息</th>
                        <th>采购数量</th>
                        <th>入库数量</th>
                    </tr>
                    </thead>
                    <tbody id="r-table">

                    </tbody>
                </table>
            </div>
        </div>
    </script>
    <script type="text/javascript">
        $(function () {
            //$('table tr:not(:first)').remove();
            var len = $('table tr').length;
            for (var i = 1; i < len; i++) {
                $('table tr:eq(' + i + ') td:first').text(i);
            }
            $('.detail').click(function () {
                var id = $(this).attr('data-id');
                // ..ajax 获取数据 完成后弹出
                Tips.open({
                    title: '已入库详情',
                    content: $('#tpl-1').html(),
                    render: function () {
                        // 处理数据 给模板中变量赋值
                        // ..
                        var dataObj = {"id": id};
                        $.ajax({
                            type: "POST",
                            url: "/ajax_stock_in/detail",
                            data: JSON.stringify(dataObj),
                            dataType: 'json',
                            contentType: 'application/json',
                            success: function (data) {
                                $("#r-number").text(data.data.billNo);
                                $("#r-time").text(data.data.billDate);
                                $("#r-count").text(data.data.totalQuantity);
                                $("#r-name").text(data.data.userName);
                                $("#r-trader").text(data.data.contactName);
                                var item = data.data.items;
                                var str = "";
                                for (var i = 0; i < item.length; i++) {
                                    str = str + "<tr>" +
                                        "<th >" + item[i].specNumber + "</th>" +
                                        "<th>" + item[i].goodsName + "</th>" +
                                        "<th>颜色：<span >"+item[i].colorValue+"</span>\n 尺码：<span>"+item[i].sizeValue+"</span>" + item[i].goodsName + "</th>" +
                                        "<th>" + item[i].locationName + "</th>" +
                                        "<th >" + item[i].quantity + "</th>" +
                                        "<th >" + item[i].inQuantity + "</th>" +
                                        "</tr>";
                                }
                                $("#r-table").html(str);
                            }
                        });
                    },
                    define: function () {
                        // ..检验

                    }
                });
            });

            $(".print").click(function () {
                var id = $(this).attr("data-id");
                console.log(id);
                //iframe层

                layer.open({
                    type: 2,
                    title: '打印采购单',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['940px', '90%'],
                    content: '/purchase/put_detail?id=' + id //iframe的url
                });
            })

        });
        layui.use(['laydate', 'layer'], function () {
            var laydate = layui.laydate;
            var layer = layui.layer;
            //执行一个laydate实例
            laydate.render({
                elem: '.date' //指定元素
            });
            laydate.render({
                elem: '.date1' //指定元素
            });
        });
    </script>
</div>
</body>
<html>
